package com.portal.cwegportal.mapper;

import com.portal.cwegportal.input.addressbook.GetAddressBookInput;
import com.portal.cwegportal.model.AddressBook;
import com.portal.cwegportal.model.AddressBookDto;
import com.portal.cwegportal.model.NewsCollege;
import com.portal.cwegportal.model.TreeBuilder;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@org.apache.ibatis.annotations.Mapper
@Repository
public interface AddressBookMapper extends Mapper<AddressBook> {


    //@Select("select id,id as `key`,id as `value`,name,name as title,parent_id as pid from address_book where type_id=1 and id=1  UNION ALL " +
            //"select id,id as `key`,id as `value`,name,name as title,parent_id as pid from address_book where FIND_IN_SET(id,getChildrenAddressBook(#{parentId})) and type_id=1 and user_code=#{userCode} and name like concat ('%',#{title},'%') ")
    //List<TreeBuilder.Node> selectOrgList(GetAddressBookInput input);

    @Select("select id,id as `key`,id as `value`,name,name as title,parent_id as pid from address_book where type_id=1 and id=1  UNION ALL " +
            "select id,id as `key`,id as `value`,name,name as title,parent_id as pid from address_book where type_id=1 and user_code=#{userCode} ")
    List<TreeBuilder.Node> selectOrgList(GetAddressBookInput input);

    @Select("<script>"
            +
            "select *,id as `key`,id as `value`,name,name as title from address_book where type_id=2 and user_code=#{userCode} and parent_id=#{parentId} and name like concat ('%',#{title},'%') and is_deleted=0 "
            +
            "<if test='keyword!=null and keyword!=&apos;&apos;'>"
            +
            " and (name like concat ('%',#{keyword},'%') or phone like concat ('%',#{keyword},'%') or work_phone like concat ('%',#{keyword},'%') or user_code like concat ('%',#{keyword},'%') ) "
            +
            "</if>"
            +"</script>"
    )
    List<AddressBookDto> selectPersonList(GetAddressBookInput input);

}
